from Selenium2Library.keywords.keywordgroup import KeywordGroup
import time
import datetime
from Selenium2Library.locators import ElementFinder

class _BreezeTransactionListKeywords(KeywordGroup):
    """Library for Breeze Transaction List Keywords purposes.
    
    This library is used in Breeze projects.
    """
    def __init__(self):
        """Does nothing. init only"""
        print '_BreezeTransactionListKeywords.__init__'

    def read_ibnk_accounts_count(self):
        """Used in transaction-list.tsv it is used for transaction list of an account/card comparing between BMW and iBanking.
        
        First compare the first account then compare the first card.
        
        Count the number of accounts in ibanking and used this number to calculate position of card and read card in BMW for comparing.
        """
        return self._run('read_ibnk_accounts_count')
    
    def _read_ibnk_accounts_count_pk(self):
        '''Find no of accounts and then use this number to find the first credit card record in BMW for credit card transaction comparing.
        '''
        rows = self._element_find("//table[@class='tbl_listing']", False, False)

        accountlist = []
        
        for r in rows: #TODO
            if r.find_elements_by_xpath("./tbody/tr[1]/th[2]")[0].text == 'Accounts':
                accountlist = r.find_elements_by_xpath("./tbody/tr[@class='tbl_listing_bottom']")
        self._info(len(accountlist))
        return int(len(accountlist))
    
    def _read_ibnk_accounts_count_id(self):
        '''Find no of accounts and then use this number to find the first credit card record in BMW for credit card transaction comparing.
        '''
        self.select_links_frame_ibanking()
        self.current_frame_contains("Accounts")
        
        element = self._element_find("//a[@id='nav_ML4']", True, False)
        self._info(element)
        element.click()
        self.select_top_frame_ibanking()
        self.wait_until_page_contains("Please click on \"Account Number\" to view details.")
        
        rows = self._element_find("//*[@id='acclist']/tbody/tr", False, False)
        self._info(rows)
        return len(rows)
            
    def read_bmw_transaction(self):
        """Used in transaction-list.tsv it is used for transaction list of an accountcomparing between BMW and iBanking.
        
        This keyword is used for read the transaction list of account in BMW.
        
        See `Read BMW Card Transaction`, `Read Ibnk Account Transaction` and `Read Ibnk Card Transaction`
        """
        return self._run('read_bmw_transaction')
    
    def _read_bmw_transaction_sg(self):
        '''For BMW ID, please refer to BMW PK if not work here
        '''  
        accountName = self.get_matching_xpath_count("//div[@class='ember-view']/div[1][@class='headings spaced']/ul[@class='two-sections more-information']/li[1]/p")
        #self._info(countdate)
        accountNumber = self.get_matching_xpath_count("//div[@class='ember-view']/div[1][@class='headings spaced']/ul[@class='two-sections more-information']/li[1]/h3")
        #self._info(counttrans)
        
        name = self._element_find("//table[@class='width-type-8 l-r']/tbody/tr/td[1]", False, False)
        balance = self._element_find("//table[@class='width-type-8 l-r']/tbody/tr/td[2] ", False, False)
        date = self._element_find("//thead", False, False)
         
        accounts = []
        for i in xrange(len(name)): #TODO
            self._info(date[i].text + "-" + name[i].text + "-" + balance[i].text)
            accounts.append([name[i].text,
                            balance[i].text,
                            date[i].text])

        self._info(len(accounts))
        return accounts

    def _read_bmw_transaction_pk(self):
  
        countdate = self.get_matching_xpath_count("//div[@class='list-view']/dl/dt[@id]")
        #self._info(countdate)
        counttrans = self.get_matching_xpath_count("//div[@class='list-view']/dl/dd[@id]")
        #self._info(counttrans)
        
        name = self._element_find("//div[@class='list-view']/dl/dd/a/span[@class='info-primary']", False, False)
        balance = self._element_find("//div[@class='list-view']/dl/dd/a/span[2] ", False, False)
        date = self._element_find("//div[@class='list-view']/dl/dd[@id]", False, False)
         
        accounts = []
        for i in xrange(len(name)): #TODO
            date1 = self.get_element_attr(date[i], "id").split(":")[0]
            
            #2011-10-01 to 01/10/2011
            year = date1.split("-")[0]
            month = date1.split("-")[1]
            day = date1.split("-")[2]
            
            #here the "if" condition is try to only append the immediate transaction to accounts as scheduled transaction records cannot match with them on ibanking.
            #if the issue resolved, we can uncomment "read scheduled transactions if any." part in read_ibnk_account_transaction
            if int(year) <= 2011 and int(month) <= 10 and int(day) <= 01:
                date1 = day + "/" + month + "/" + year + " "
                self._info(date1 + "-" + name[i].text + "-" + balance[i].text)
                accounts.append([name[i].text,
                                balance[i].text,
                                date1])
            else:
                pass
                            
        self._info(len(accounts)) 
        return accounts

    def _read_bmw_transaction_id(self):
        '''For BMW ID, please refer to BMW PK if not work here
        '''  
        countdate = self.get_matching_xpath_count("//div[@class='list-view']/dl/dt[@id]")
        #self._info(countdate)
        counttrans = self.get_matching_xpath_count("//div[@class='list-view']/dl/dd[@id]")
        #self._info(counttrans)
        
        name = self._element_find("//div[@class='list-view']/dl/dd/a/span[@class='info-primary']", False, False)
        balance = self._element_find("//div[@class='list-view']/dl/dd/a/span[2] ", False, False)
        date = self._element_find("//div[@class='list-view']/dl/dd[@id]", False, False)
         
        accounts = []
        for i in xrange(len(name)): #TODO
            self._info(self.get_element_attr(date[i], "id") + "-" + name[i].text + "-" + balance[i].text)
            accounts.append([name[i].text,
                            balance[i].text,
                            self.get_element_attr(date[i], "id")])

        self._info(len(accounts))
        return accounts

    def read_bmw_card_transaction(self):
        """Used in transaction-list.tsv it is used for transaction list of a card comparing between BMW and iBanking.
        
        This keyword is used for read the transaction list of card in BMW.
        
        See `Read BMW Transaction`, `Read Ibnk Account Transaction` and `Read Ibnk Card Transaction`
        """
        return self._run('read_bmw_card_transaction')

    def _read_bmw_card_transaction_pk(self):
  
        countdate = self.get_matching_xpath_count("//div[@class='list-view']/dl/dt[@id]")
        counttrans = self.get_matching_xpath_count("//div[@class='list-view']/dl/dd[@id]")
        
        name = self._element_find("//div[@class='list-view']/dl/dd/a/span[@class='info-primary']", False, False)
        balance = self._element_find("//div[@class='list-view']/dl/dd/a/span[2] ", False, False)
        date = self._element_find("//div[@class='list-view']/dl/dd[@id]", False, False)
         
        accounts = []
        for i in xrange(len(name)): #TODO
            date1 = self.get_element_attr(date[i], "id").split(":")[0]
            
            #2011-10-01 to 01/10/2011
            year = date1.split("-")[0]
            month = date1.split("-")[1]
            day = date1.split("-")[2]

            date1 = day + "/" + month + "/" + year + " "
            self._info(date1 + "-" + name[i].text + "-" + balance[i].text)
            accounts.append([name[i].text,
                            balance[i].text,
                            date1])
                            
        self._info(len(accounts)) 
        return accounts

    def _read_bmw_card_transaction_id(self):
  
        countdate = self.get_matching_xpath_count("//div[@class='list-view']/dl/dt[@id]")
        counttrans = self.get_matching_xpath_count("//div[@class='list-view']/dl/dd[@id]")
        
        name = self._element_find("//div[@class='list-view']/dl/dd/a/span[@class='info-primary']", False, False)
        balance = self._element_find("//div[@class='list-view']/dl/dd/a/span[2] ", False, False)
        date = self._element_find("//div[@class='list-view']/dl/dd[@id]", False, False)
         
        accounts = []
        for i in xrange(len(name)): #TODO
            date1 = self.get_element_attr(date[i], "id").split(":")[0]
            
            #2011-10-01 to 01/10/2011
            year = date1.split("-")[0]
            month = date1.split("-")[1]
            day = date1.split("-")[2]

            date1 = day + "/" + month + "/" + year + " "
            self._info(date1 + "-" + name[i].text + "-" + balance[i].text)
            accounts.append([name[i].text,
                            balance[i].text,
                            date1])
                            
        self._info(len(accounts)) 
        return accounts
        
    def read_ibnk_account_transaction(self):
        """Used in transaction-list.tsv it is used for transaction list of an account/card comparing between BMW and iBanking.
        
        This keyword is used for read the account transaction list in Ibanking.
        
        See `Read BMW Transaction` and `Read Ibnk Card Transaction`
        """
        return self._run('read_ibnk_account_transaction')
    
    def _read_ibnk_account_transaction_pk(self):   
        transactions1 = []
        temp = [] 
        
        #click to show the first account's transaction
        element = self._element_find("//*[@id='printContent']/table/tbody/tr[5]/td[1]/table[1]/tbody/tr[2]/td[2]/a", True, False)
        self._info(element)
        element.click()
        self.wait_until_page_contains("Account transactions shown")

        if self._is_text_present("No transactions to display"):
            self._info("No transactions to display for account")
        else:
            #find page no for the transaction
            element = self._element_find("//*[@id='printContent']/table[2]/tbody/tr/td", False, False)
            self._info(element[0].text)
            
            #total page for transaction records Total: 44,1 of 3 page(s).
            pagecount = element[0].text.split(" ")[3]
            
            rows4 = self._element_find("//*[@id='vAcctTrxnList']/tbody/tr", False, False)
            self._info(len(rows4))

            #read transaction records in each page
            if int(pagecount) > 1:
                temp = (self._read_ibnk_account_transaction_pk_single_page(rows4, len(rows4)))
                transactions1 = transactions1 + temp
                
                for k in range(1, int(pagecount)):
                    if k == 1:
                        element = self._element_find("//*[@id='ignorePrint_paging']/tbody/tr/td/a[" + str(k) + "]", True, False)
                    elif k < 4:
                        element = self._element_find("//*[@id='ignorePrint_paging']/tbody/tr/td/a[" + str(k + 2) + "]", True, False)
                    else:
                        element = self._element_find("//*[@id='ignorePrint_paging']/tbody/tr/td/a[6]", True, False)
                    element.click()
                    self.wait_until_page_contains(str(k + 1) + " of " + str(pagecount) + " page(s).")
                    
                    rows4 = self._element_find("//*[@id='vAcctTrxnList']/tbody/tr", False, False)
                    temp = (self._read_ibnk_account_transaction_pk_single_page(rows4, len(rows4)))
                    transactions1 = transactions1 + temp
                
            elif int(pagecount) == 1:
                temp = (self._read_ibnk_account_transaction_pk_single_page(rows4, len(rows4) - 1))
                transactions1 = transactions1 + temp
            else:
                pass
                  
        return transactions1

    def _read_ibnk_account_transaction_pk_single_page(self, rows, num):
        transactions = []
    
        for i in range(0, num): #TODO
            date = rows[i].find_elements_by_xpath("./td[1]")
            description = rows[i].find_elements_by_xpath("./td[2]")
            withdrawal = rows[i].find_elements_by_xpath("./td[5]")
            deposit = rows[i].find_elements_by_xpath("./td[4]")
            amountPKR = rows[i].find_elements_by_xpath("./td[6]")
            self._info('%s> %s> %s> %s> %s>' % (date[0].text, description[0].text, withdrawal[0].text, deposit[0].text, amountPKR[0].text))
            
            if withdrawal[0].text.strip() == '':
                transactions.append([description[0].text,
                                    "PKR" + deposit[0].text.strip(),
                                    date[0].text])
            else:
                transactions.append([description[0].text,
                                    "PKR" + withdrawal[0].text.strip(),
                                    date[0].text])
        self._info(len(transactions))
        
        return transactions

    def _read_ibnk_account_scheduled_transaction_pk_single_page(self, rows, num):
        transactions = []
    
        for i in range(0, num): #TODO
            date = rows[i].find_elements_by_xpath("./td[1]")
            description = rows[i].find_elements_by_xpath("./td[6]")#Transafer Type
            amount = rows[i].find_elements_by_xpath("./td[5]")
            fromaccount = rows[i].find_elements_by_xpath("./td[2]")
            toaccount = rows[i].find_elements_by_xpath("./td[3]")
            beneficiary = rows[i].find_elements_by_xpath("./td[4]")
            
            transactions.append([description[0].text,
                                "PKR" + amount[0].text.split(" ")[1].strip(),
                                date[0].text])
        self._info(len(transactions))
        
        return transactions
            
    def _read_ibnk_account_transaction_id(self):
        self.select_links_frame_ibanking()
        self.current_frame_contains("Accounts")
        
        #click "Accounts" link in left navigation bar
        element = self._element_find("//a[@id='nav_ML4']", True, False)
        element.click()
        self.select_top_frame_ibanking()
        self.wait_until_page_contains("Please click on \"Account Number\" to view details.")
        
        #click to show the first account's transaction
        element = self._element_find("//*[@id='acclist']/tbody/tr[1]/td[2]", True, False)
        element.click()
        self.wait_until_page_contains("Account Transaction Details")
        
        #click dropdown button
        element = self._element_find("//*[@id='pagePrintTag']/table/tbody/tr[1]/td/table/tbody/tr[6]/td[3]/select[2]", True, False)
        element.click()
        
        #click to set a month
        self._info(datetime.datetime.now())
        self._info(str(datetime.datetime.now()).split("-")[1])
        self._info(int(str(datetime.datetime.now()).split("-")[1]))
        
        month = int(str(datetime.datetime.now()).split("-")[1]) - 2
        self._info(int(str(datetime.datetime.now()).split("-")[1]) - 2)
        element = self._element_find("//*[@id='pagePrintTag']/table/tbody/tr[1]/td/table/tbody/tr[6]/td[3]/select[2]/option[" + str(month) + "]", True, False)
        self._info(element.text)
        element.click()
        
        #click the show button
        element = self._element_find("//*[@id='pagePrintTag']/table/tbody/tr[1]/td/table/tbody/tr[8]/td[4]/table/tbody/tr/td/a/span", True, False)
        element.click()
        
        self.wait_until_page_contains("OPENING BALANCE")
        
        #find page no for the transaction
        element = self._element_find("//*[@id='pagePrintTag']/table/tbody/tr[8]/td/table/tbody/tr/td[2]/span/b", False, False)
        self._info(element[0].text)
        
        #total page for transaction records
        pagecount = element[0].text.split(" ")[3]
        self._info(pagecount)

        rows4 = self._element_find("//div[@id='pagePrintTag']/table/tbody/tr[4]/td/table/tbody/tr[@class='table_row_white' or @class='table_row_grey']", False, False)
        self._info(len(rows4))
            
        transactions1 = []
        
        #read the transaction record in each page. if not work here, please refer to "_read_ibnk_account_transaction_pk" as there is finished.
        #but please note, cannot copy directly, as there is slight difference between ID and PK  
        #mainly page number format and actual argument for single page call      
        if int(pagecount) > 1:
            transactions1.append([self._read_ibnk_account_transaction_id_single_page(rows4, len(rows4))])
            for k in range(1, int(pagecount)):
                element = self._element_find("//*[@id='Tip1']/a[" + str(k + 1) + "]", True, False)
                self._info(element)
                self._info(element.text)
                element.click()
                self.wait_until_page_contains("Page  " + str(k + 1) + " of " + str(pagecount))
                if k == int(pagecount) - 1:#need to not to loop the last line, as there is no transaction in this line, the index will out of range if do not minus the last line in last page
                    rows4 = self._element_find("//div[@id='pagePrintTag']/table/tbody/tr[4]/td/table/tbody/tr[@class='table_row_white' or @class='table_row_grey']", False, False)
                    transactions1.append([self._read_ibnk_account_transaction_id_single_page(rows4, len(rows4) - 1)])
                else:
                    rows4 = self._element_find("//div[@id='pagePrintTag']/table/tbody/tr[4]/td/table/tbody/tr[@class='table_row_white' or @class='table_row_grey']", False, False)
                    transactions1.append([self._read_ibnk_account_transaction_id_single_page(rows4, len(rows4))])                    
        elif int(pagecount) == 1:
            transactions1.append([self._read_ibnk_account_transaction_id_single_page(rows4, len(rows4) - 1)])
        else:
            pass
        return transactions1
    
    def _read_ibnk_account_transaction_id_single_page(self, rows, num):
        transactions = []
    
        for i in range(2, num): #TODO
            date = rows[i].find_elements_by_xpath("./td[2]")
            description = rows[i].find_elements_by_xpath("./td[4]")
            withdrawal = rows[i].find_elements_by_xpath("./td[5]")
            deposit = rows[i].find_elements_by_xpath("./td[7]")
            amountIDR = rows[i].find_elements_by_xpath("./td[8]")
            self._info('%s> %s> %s> %s> %s>' % (date[0].text, description[0].text, withdrawal[0].text, deposit[0].text, amountIDR[0].text))
                    
            transactions.append([description[0].text,
                                amountIDR[0].text,
                                date[0].text])
        self._info(len(transactions))
        
        return transactions

    def read_ibnk_card_transaction(self):
        """Used in transaction-list.tsv it is used for transaction list of an account/card comparing between BMW and iBanking.
        
        This keyword is used for read the card transaction list in Ibanking.
        
        See `Read BMW Transaction` and `Read Ibnk Account Transaction`
        """
        return self._run('read_ibnk_card_transaction')
    
    def _read_ibnk_card_transaction_pk(self):
#        element = self._element_find("//*[@id='parentMenuHead']/a", True, False)
#        element.click()
#        self.wait_until_page_contains("You last logged in at")
        
        #click to show the first card's transaction
        element = self._element_find("//*[@id='parentMenuHead'][2]/a/table/tbody/tr/td", True, False)
        self._info(element)
        element.click()
        self.wait_until_page_contains("Cards Summary")
        
        element = self._element_find("//*[@id='parentMenuContentSelected']/div[2]/a/table/tbody/tr/td", True, False)
        self._info(element)
        element.click()
        self.wait_until_page_contains("Select Card:")
        
        '''Drop down list selection for past 90 days select, please refer to _read_ibnk_account_transaction_id
        '''
        
#        if No transactions to display
        #find page no for the transaction
        element = self._element_find("//*[@id='printContent']/table[2]/tbody/tr/td", False, False)
        self._info(element[0].text)
        
        #total page for transaction records Total: 24,1 of 2 page(s)..
        pagecount = element[0].text.split(" ")[3]
        self._info(pagecount)

        transactions1 = list()   
        temp = list()        

        rows4 = self._element_find("//*[@id='cardTransactionVO']/tbody/tr", False, False)
        self._info(len(rows4))
                   
        if int(pagecount) > 1:
            temp = (self._read_ibnk_card_transaction_pk_single_page(rows4, len(rows4), 0))
            transactions1 = transactions1 + temp
            for k in range(1, int(pagecount)):
                if k == 1:
                    element = self._element_find("//*[@id='ignorePrint_paging']/tbody/tr/td/a[" + str(k) + "]", True, False)
                elif k < 4:
                    element = self._element_find("//*[@id='ignorePrint_paging']/tbody/tr/td/a[" + str(k + 2) + "]", True, False)
                else:
                    element = self._element_find("//*[@id='ignorePrint_paging']/tbody/tr/td/a[6]", True, False)
                element.click()
                self.wait_until_page_contains(str(k + 1) + " of " + str(pagecount) + " page(s).")
                
#                if k==int(pagecount)-1:#need to not to loop the last line of last page, as there is no transaction in this line, the index will out of range if do not minus the last line in last page
#                    rows4 = self._element_find("//*[@id='vAcctTrxnList']/tbody/tr", False, False)
#                    transactions1.append([self._read_ibnk_card_transaction_pk_single_page(rows4,len(rows4)-1)])
#                else:
                rows4 = self._element_find("//*[@id='cardTransactionVO']/tbody/tr", False, False)
                temp = (self._read_ibnk_card_transaction_pk_single_page(rows4, len(rows4), 0))
                transactions1 = transactions1 + temp                    
        elif int(pagecount) == 1:
            temp = (self._read_ibnk_card_transaction_pk_single_page(rows4, len(rows4) - 1, 1))
            transactions1 = transactions1 + temp
        else:
            pass
        return transactions1

    def _read_ibnk_card_transaction_pk_single_page(self, rows, num, start):
        transactions = []
        #12/12    ONLINE CASH ADV     -     6.68 DR
        #when have time, need to implement "No transactions to display"
    
        for i in range(start, num): #TODO
            date = rows[i].find_elements_by_xpath("./td[1]")
            description = rows[i].find_elements_by_xpath("./td[2]")
#            withdrawal= rows[i].find_elements_by_xpath("./td[5]")
#            deposit= rows[i].find_elements_by_xpath("./td[4]")
            amountPKR = rows[i].find_elements_by_xpath("./td[4]")
            self._info('%s> %s> %s>' % (date[0].text, description[0].text, amountPKR[0].text))

            transactions.append([description[0].text,
                                "PKR" + amountPKR[0].text.split(" ")[0],
                                date[0].text])

        self._info(len(transactions))
        
        return transactions
             
    def _read_ibnk_card_transaction_id(self):
        self.select_links_frame_ibanking()
        self.current_frame_contains("Accounts")
        
        element = self._element_find("//*[@id='nav_ML300']", True, False)
        element.click()
        self.select_top_frame_ibanking()
        self.wait_until_page_contains("Credit Cards")
        
        element = self._element_find("//tr[@class='table_row_white']/td[2]", True, False)
        element.click()
        self.wait_until_page_contains("Card Transaction Details")
        
        transactions = []

        #cards transactions. but here is only for one page. have not implemented the get card transaction for each page.
        #no paging data when writing this keyword. can refer to "_read_ibnk_account_transaction_pk" for read transaction for each page.
        rows3 = self._element_find("//td[@valign='top']/table[@id='accountsViewTable']/tbody/tr[@height='27px']", False, False)
        self._info(len(rows3))
        for i in range(1, len(rows3) - 1): #TODO
            date = rows3[i].find_elements_by_xpath("./td[1]")
            description = rows3[i].find_elements_by_xpath("./td[2]")
            currency = rows3[i].find_elements_by_xpath("./td[3]")
            amountIDR = rows3[i].find_elements_by_xpath("./td[5]")
            self._info(date[0].text)
            self._info(description[0].text)
            self._info(currency[0].text)
            self._info(amountIDR[0].text)
            
            transactions.append([description[0].text,
                            amountIDR[0].text,
                            date[0].text])
        self._info(len(transactions))
        return transactions
              
    def _read_ibnk_transaction_id_bak(self, accno):
        self.select_links_frame_ibanking()
        self.current_frame_contains("Accounts")
        
        element = self._element_find("//a[@id='nav_ML4']", True, False)
        element.click()
        self.select_top_frame_ibanking()
        self.wait_until_page_contains("Please click on \"Account Number\" to view details.")
        
        rows = self._element_find("//*[@id='acclist']/tbody/tr", False, False)
        self._info(len(rows))
        accountno = len(rows)
        
        transactions = []
        
        if accno <= accountno:
            
            element = self._element_find("./td[2]", True, False)
            element.click()
            self.wait_until_page_contains("Transaction Details")
            
            #accounts transactions
            rows4 = self._element_find("//table[@id='accountsViewTable']/tbody/tr[@height='27px']", False, False)
            for r4 in rows4: #TODO
                date = r4.find_elements_by_xpath("./td[2]")
                description = r4.find_elements_by_xpath("./td[4]")
                withdrawal = r4.find_elements_by_xpath("./td[5]")
                deposit = r4.find_elements_by_xpath("./td[7]")
                amountIDR = r4.find_elements_by_xpath("./td[8]")
                self._info('%s> %s> %s> %s> %s>' % (date[0].text, description[0].text, withdrawal[0].text, deposit[0].text, amountIDR[0].txt))
                
                transactions.append([date[0].text,
                                 description[0].text,
                                 withdrawal[0].text.split(' ')[1],
                                 deposit[0].text.split(' ')[2],
                                 amountIDR[0].text.split(' ')[2], ])
            self._info(len(transactions))
        
        else:           
            self.select_links_frame_ibanking()
            element = self._element_find("//*[@id='nav_ML300']", True, False)
            element.click()
            self.select_top_frame_ibanking()
            self.wait_until_page_contains("Credit Cards")
            
            rows2 = self._element_find("//tr[@class='table_row_white']", False, False)
            cardno = len(rows2)
            if accno > (accountno + cardno):
                return null
            
            element = self._element_find("./td[2]", True, False)
            element.click()
            self.wait_until_page_contains("Transaction Details")

            #cards transactions
            rows3 = self._element_find("//table[@id='accountsViewTable']/tbody/tr[@height='27px']", False, False)
            for r3 in rows3: #TODO
                date = r3.find_elements_by_xpath("./td[1]")
                description = r3.find_elements_by_xpath("./td[2]")
                currency = r3.find_elements_by_xpath("./td[3]")
                amountIDR = r3.find_elements_by_xpath("./td[5]")
    
                self._info('%s> %s> %s>' % (date[0].text, description[0].text, currency[0].text, amountIDR[0].txt))
                transactions.append([date[0].text,
                                description[0].text,
                                currency[0].text.strip(),
                                amountIDR[0].txt])
            self._info(len(transactions))
            return transactions
        
#below keywords are not used in any robot cases. Just try out for whether the keyword call can be parametered. from current results, it cannot be. currently use "if" condition   
    def _ibnk_page_turning_pk(self, rows4Xpath, pagecount, pageXpath, singlepagecall):
        
        transactions1 = []
        temp = [] 
        
        rows4 = self._element_find(rows4Xpath, False, False)
        self._info(len(rows4))
        
        if int(pagecount) > 1:
            if singlepagecall == "_read_ibnk_account_transaction_pk_single_page":
                temp = self._read_ibnk_account_transaction_pk_single_page(rows4, len(rows4))#see here, cannot make the keyword parameterd. only can be judged by if confidition.
            elif singlepagecall == "_read_ibnk_account_scheduled_transaction_pk_single_page":
                temp = self._read_ibnk_account_scheduled_transaction_pk_single_page(rows4, len(rows4))
            else:
                pass
            transactions1 = transactions1 + temp
            
            for k in range(1, int(pagecount)):
                if k == 1:
                    element = self._element_find(pageXpath+"[" + str(k) + "]", True, False)
                else:
                    element = self._element_find(pageXpath+"[" + str(k + 2) + "]", True, False)
                element.click()
                self.wait_until_page_contains(str(k + 1) + " of " + str(pagecount) + " page(s).")
                
                rows4 = self._element_find(rows4Xpath, False, False)
                
                if singlepagecall == "_read_ibnk_account_transaction_pk_single_page":
                    temp = self._read_ibnk_account_transaction_pk_single_page(rows4, len(rows4))
                elif singlepagecall == "_read_ibnk_account_scheduled_transaction_pk_single_page":
                    temp = self._read_ibnk_account_scheduled_transaction_pk_single_page(rows4, len(rows4))
                else:
                    pass
                
                transactions1 = transactions1 + temp
            
        elif int(pagecount) == 1:
            if singlepagecall == "_read_ibnk_account_transaction_pk_single_page":
                temp = self._read_ibnk_account_transaction_pk_single_page(rows4, len(rows4))
            elif singlepagecall == "_read_ibnk_account_scheduled_transaction_pk_single_page":
                temp = self._read_ibnk_account_scheduled_transaction_pk_single_page(rows4, len(rows4))
            else:
                pass
            transactions1 = transactions1 + temp
        else:
            pass
        return transactions1
    
    def transaction_pk(self):   
        '''This is a try out. Used to verify whether the keyword call can be parametered. From my try, it cannot be. 
        Only can be parametered and then compared with if condition to verify which keyword you want to call.
        
        See _ibnk_page_turning_pk please.
        '''
        #click to show the first account's transaction
        element = self._element_find("//*[@id='printContent']/table/tbody/tr[5]/td[1]/table[1]/tbody/tr[2]/td[2]/a", True, False)
        self._info(element)
        element.click()
        self.wait_until_page_contains("Account transactions shown")
               
        #total page for transaction records Total: 44,1 of 3 page(s).
        if self._is_text_present("No Transaction Available"):
            self._info("No Beneficiaries Available IFT")
        else:
            #find page no for the transaction
            element = self._element_find("//*[@id='printContent']/table[2]/tbody/tr/td", False, False)
            self._info(element[0].text)
            
            #total page for transaction records Total: 44,1 of 3 page(s).
            pagecount = element[0].text.split(" ")[3]
            rows4Xpath = "//*[@id='vAcctTrxnList']/tbody/tr"
            pageXpath = "//*[@id='ignorePrint_paging']/tbody/tr/td/a"
            singlepagecall = "_read_ibnk_account_transaction_pk_single_page"#see here, keyword call
            self._info(singlepagecall)
            
            transactions = self._ibnk_page_turning_pk(rows4Xpath, pagecount, pageXpath, singlepagecall)              
        return transactions


